from selenium import webdriver
from selenium.webdriver.edge.options import Options

class WebDriverFactory:
    def get_driver(browser_type="edge", headless=True, implicit_wait_time=30):
        """获取浏览器驱动"""
        if browser_type.lower() == "edge":
            options = Options()
            options.add_argument('--ignore-certificate-errors')
            options.add_argument('--allow-running-insecure-content')
            
            if headless:
                options.add_argument('--headless')
                options.add_argument('--disable-gpu')
                options.add_argument('--no-sandbox')
                options.add_argument('--disable-dev-shm-usage')
            
            driver = webdriver.Edge(options=options)
            driver.maximize_window()
            driver.implicitly_wait(implicit_wait_time)
            return driver
        else:
            raise ValueError(f"Unsupported browser type: {browser_type}")
